<?php
class My_API_ss31_Users
{
    private $_config;

    public function __construct($gameId = null)
    {
        if(!isset($gameId) || !file_exists(CONFIG_PATH2 . "/$gameId.ini")){
            return false;
        }
        $config = new Zend_Config_Ini(CONFIG_PATH2 . "/$gameId.ini",APPLICATION_ENV);
        $this->_config = $config;
    }
    
    public function getUsersByServerId($listUser, $gameId)
    {
		$infoUsers = array();
        $modelSs31=new Default_Model_Ss31gamerole($gameId);
        $dataRole=$modelSs31->getData($listUser);
        if($dataRole){
            $dataRole=$dataRole->toArray();
            if(isset($this->_config->statistics->value)){
                $title=$this->_config->statistics->value->toArray();
                foreach($title as $key=>$val){
                    if(isset($dataRole[$key])){
                        if($key=='roleAllLevel'){
                           
                            $dataRole[$key]=json_decode($dataRole[$key], True);   
                        }
                        $infoUsers[$key]=$dataRole[$key];
                    }
                }
            }
           
            return $infoUsers;
        }
        else{
            return;
        }
    }
    
    public function getUsernameByRolename($RoleName, $gameId){
        $i = 0;
		$infoUsers = array();
        $modelSs31=new Default_Model_Ss31gamerole($gameId);
        $dataRole=$modelSs31->checkUserName($RoleName);
        if($dataRole){
            $dataRole=$dataRole->toArray();
            $infoUsers['username']=$dataRole['username'];
            if(isset($this->_config->statistics->value)){
                $title=$this->_config->statistics->value->toArray();
                foreach($title as $key=>$val){
                    if(isset($dataRole[$key])){
                        if($key=='roleAllLevel'){
                            $dataRole[$key]=json_decode($dataRole[$key],True);
                        }
                        $infoUsers[$key]=$dataRole[$key];
                    }
                }
            }
            return $infoUsers;
        }
		else{
            return;
        }
    }
}